<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>正则表达式中lastIndex属性</title>
</head>
<body>
    <script>
        let hd = "jklsahgkgfhaskd";

        // 在全局g模式下，lastIndex会+1
        let reg = /\w/g;
        console.log(reg.lastIndex);
        console.log(reg.exec(hd));
        console.log(reg.lastIndex);
        console.log(reg.exec(hd));

        while(res = reg.exec(hd)){
            console.log(res);
        }
    </script>
</body>
</html>